package com.scorpio.web.controller.system;

import com.scorpio.common.annotation.RepeatSubmit;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.AjaxResult;
import com.scorpio.common.utils.verification.AddGroup;
import com.scorpio.common.utils.verification.DefaultGroup;
import com.scorpio.common.utils.verification.UpdateGroup;
import com.scorpio.system.domain.SysOss;
import com.scorpio.system.service.ISysOssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/oss")
public class SysOssController extends BaseController {

    @Autowired
    private ISysOssService ossService;

    @GetMapping("list")
    public AjaxResult ossList(String tableName, Long tableId) {
        List<SysOss> list = ossService.selectList(tableName,tableId);
        return AjaxResult.success(list);
    }

    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated(value = {DefaultGroup.class, AddGroup.class}) @RequestBody SysOss entity) {
        return toAjax(ossService.add(entity));
    }

    @GetMapping(value = "/{tableName}/{id}")
    public AjaxResult getInfo(@PathVariable String tableName, @PathVariable Long id) {
        return AjaxResult.success(ossService.selectLatest(tableName,id));
    }

    @PutMapping
    public AjaxResult edit(@Validated(value = {DefaultGroup.class, UpdateGroup.class}) @RequestBody SysOss entity) {
        return toAjax(ossService.update(entity));
    }

    @DeleteMapping("/{tableName}/{tableId}/{ids}")
    public AjaxResult remove(@PathVariable String tableName,@PathVariable Long tableId, @PathVariable Long[] ids) {
        return toAjax(ossService.deleteByIds(tableName,tableId, ids));
    }

}
